#pragma once

#include "Component.h"
#include "InputEvent.h"
#include "Timer.h"

#define MS_TO_SEC 0.001f

/**
* @file Engine.h
* @brief Singleton
*/
class Engine
{
#pragma region SINGLETON
public:
	static Engine* GetInstance()
	{
		if (instance == nullptr)
			instance = new Engine();
		return instance;
	}
	static void Kill()
	{
		if (instance != nullptr)
		{
			delete instance;
			instance = nullptr;
		}
	}
private:
	Engine();
	Engine(const Engine& other);
	~Engine();
	static Engine* instance;
	
	Engine& operator=(const Engine& other);
#pragma endregion
public:
	void Init();
	
	void SetWindowTitle(const char* title) {
		std::string s(DEFAULT_WIN_TITLE);
		s.append(title);
		SDL_SetWindowTitle(window, s.c_str());
	}

	void SetWindowSize(int w, int h) {
		SDL_SetWindowSize(window, w, h);
	}

	SDL_Renderer* GetRenderer() {
		return renderer;
	}

	void Start();
	void Quit() { quit = true; }

private:
	SDL_Event* event;
	SDL_Window* window;
	SDL_Renderer* renderer;
	bool quit;
	bool isInitialized;

	void SetRenderClear(int r, int g, int b, int a)
	{
		SDL_SetRenderDrawColor(renderer, r, g, b, a);
	}

	void Run();
	void Update(float dt);
	void Draw();
	void Stop();
};

